package cn.itcast.service.impl;

import cn.itcast.mapper.ReportMapper;
import cn.itcast.pojo.*;
import cn.itcast.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
public class ReportServiceImpl implements ReportService {
    @Autowired
    private ReportMapper reportMapper;

    /*    *//*    @Override
        public Result empGenderData() {
            List<Report> reports = reportMapper.empGenderData();
            *//**//*for (Report report : reports) {
            if (report.getName().equals("1")) {
                report.setName("男性员工");
            } else {
                report.setName("女性员工");
            }
        }*//**//*
        return Result.success("success", reports);
    }*/
    @Override
    public Result empGenderData() {
        List<Map<String, Object>> maps = reportMapper.empGenderData();
        System.out.println(maps);
        return Result.success("success", maps);
    }

    @Override
    public Result empJobData() {

        List<Map<String, Object>> list = reportMapper.empCountDataPro();
        for (Map<String, Object> stringObjectMap : list) {
            System.out.println(stringObjectMap);
        }
        List<Object> job = list.stream().map(stringObjectMap -> stringObjectMap.get("jobName")).toList();

        List<Object> count = list.stream().map(stringObjectMap -> stringObjectMap.get("count")).toList();

        JobCount jobCount = new JobCount(job, count);

        return Result.success("统计成功", jobCount);
    }

/*    @Override
    public Result empJobData() {

        List<EmpJob> empJobs = reportMapper.empCountDataPro();
        JobCount jobCount = new JobCount();
        ArrayList<String> jobList = new ArrayList<>();
        ArrayList<Integer> dataList = new ArrayList<>();

        //1.遍历empjobs集合,将数据设置到jobList和dataList集合中
        empJobs.forEach(empjiob -> {
            jobList.add(empjiob.getJobName());
            dataList.add(empjiob.getCount());
        });
        //2.将数据设置到report对象中,并返回
        jobCount.setJobList(jobList);
        jobCount.setDataList(dataList);
        return Result.success("统计成功", jobCount);
    }*/

    @Override
    public Result studentDegreeData() {
        List<DegreeCount> degreeCount = reportMapper.studentDegreeData();


        return Result.success("统计成功", degreeCount);
    }

    @Override
    public Result studentCountData() {
        List<Map<String, Object>> list = reportMapper.studentCountData();

        List<Object> name = list.stream().map(map -> map.get("name")).toList();
        List<Object> count = list.stream().map(map -> map.get("count")).toList();


        return Result.success("统计成功", new StudentCount(name, count));
    }
/*    @Override
    public Result studentCountData() {
        List<StudentClazz> list = reportMapper.studentCountData();
        ArrayList<String> nameList = new ArrayList<>();
        ArrayList<Integer> countList = new ArrayList<>();
        list.forEach(s -> {
            nameList.add(s.getName());
            countList.add(s.getCount());
        });

        return Result.success("统计成功", new StudentCount(nameList, countList));
    }*/

/*    @Override
    public Result empJobData() {
        List<String> jobList = reportMapper.empJobData();
        jobList.set(0, "讲师");
        jobList.set(1, "学工主管");
        jobList.set(2, "班主任");
        jobList.set(3, "咨询师");
        jobList.set(4, "其他");
        jobList.set(5, "教研主管");
        System.out.println(jobList);
        List<Integer> dataList = reportMapper.empCountData();
        return Result.success("统计成功", new Report(jobList, dataList));
    }*/
}
